﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CivilRegistry.ControlledModel;
using CivilRegistry.Common;

namespace CivilRegistry
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            var loggedInUser = SessionHandler.CurrentSession.User;
            var user = ControlledModel.User.GeUser(loggedInUser.UserName, txtCurrentPassword.Text);
            if (user != null)
            {
                try
                {
                    loggedInUser.ChangePassword(txtNewPassword.Text);
                    Response.Redirect("~/Default.aspx");
                }
                catch (Exception ex)
                {
                    Logger.ErrorLogger.Log(ex);
                    lblStatus.Text = "An unexpected error occured on the application. Please contact the appropriate technical candidate for more information.";
                }
            }
            else
            {
                lblStatus.Text = "";
            }
        }
    }
}